home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.7 KB | 495 lines | [TEXT/MPS ] |
- //
- // File: SLSUSink.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: © 1993-1996 by Apple Computer, Inc., all rights reserved.
- //
-
- #include "FWOS.hpp"
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) & !defined(SOMCorba_h)
- #include <somcorba.h>
- #endif
-
-
- /*
- * This file was generated by the SOM Compiler.
- * Generated using:
- * SOM Emitter emitxtm.dll: 2.33
- */
-
- #define FW_OStorageUnitSink_Class_Source
- #include "SLSUSink.xih"
-
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodmisc
- #endif
-
- //========================================================================================
- // CLASS FW_CPrivSUSinkRep
- //========================================================================================
-
- class FW_CPrivSUSinkRep
- {
- public:
- FW_DECLARE_AUTO(FW_CPrivSUSinkRep)
-
- FW_CPrivSUSinkRep(Environment* ev,
- ODStorageUnitView* storageUnitView);
- FW_CPrivSUSinkRep(Environment* ev,
- ODStorageUnit* storageUnit,
- ODPropertyName propertyName,
- ODValueType valueType);
-
- ~FW_CPrivSUSinkRep();
-
- public:
- // ----- Random Access Sink Protocol
- long GetPosition(Environment* ev);
- void SetPosition(Environment* ev, long position);
- long GetLength(Environment* ev);
- void SetLength(Environment* ev, long length);
-
- void Read(Environment* ev, void* destination, long count);
-
- long GetWritableBytes(Environment* ev);
- void Write(Environment* ev, void* source, long count);
-
- public:
- void Acquire(Environment* ev);
-
- public:
- ODStorageUnitView* fStorageUnitView;
- FW_Boolean fOwnsView;
- };
-
- FW_DEFINE_AUTO(FW_CPrivSUSinkRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev,
- ODStorageUnitView* storageUnitView) :
- fStorageUnitView(storageUnitView),
- fOwnsView(FALSE)
- {
- Acquire(ev);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev,
- ODStorageUnit* storageUnit,
- ODPropertyName propertyName,
- ODValueType valueType) :
- fStorageUnitView(0),
- fOwnsView(TRUE)
- {
- FW_ASSERT(propertyName != NULL);
- FW_ASSERT(valueType != NULL);
-
- storageUnit->Focus(ev,
- propertyName, kODPosUndefined,
- valueType, (ODValueIndex)0, kODPosUndefined);
- fStorageUnitView = storageUnit->CreateView(ev);
-
- Acquire(ev);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep()
- {
- FW_START_DESTRUCTOR
-
- FW_SOMEnvironment ev;
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- if (fStorageUnitView)
- fStorageUnitView->GetStorageUnit(ev)->Release(ev);
- #endif
-
- if (fOwnsView)
- delete fStorageUnitView;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::GetPosition
- //----------------------------------------------------------------------------------------
-
- inline long FW_CPrivSUSinkRep::GetPosition(Environment* ev)
- {
- return fStorageUnitView->GetOffset(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::SetPosition
- //----------------------------------------------------------------------------------------
-
- inline void FW_CPrivSUSinkRep::SetPosition(Environment* ev, long position)
- {
- fStorageUnitView->SetOffset(ev, position);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::GetLength
- //----------------------------------------------------------------------------------------
-
- inline long FW_CPrivSUSinkRep::GetLength(Environment* ev)
- {
- // calling fStorageUnitView->GetSize(ev) results in a throw
- return fStorageUnitView->GetStorageUnit(ev)->GetSize(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::SetLength
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivSUSinkRep::SetLength(Environment* ev, long length)
- {
- long prevLength = GetLength(ev);
-
- if (length < prevLength)
- {
- SetPosition(ev, length);
- fStorageUnitView->DeleteValue(ev, prevLength-length);
- }
- else if (length > prevLength)
- {
- const long kSize = 128;
- char buffer[kSize] = {0};
- SetPosition(ev, prevLength);
- length -= prevLength;
- while (length > 0)
- {
- long bytes = length < kSize ? length : kSize;
- Write(ev, buffer, bytes);
- length -= bytes;
- }
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::Read
- //----------------------------------------------------------------------------------------
-
- inline void FW_CPrivSUSinkRep::Read(Environment* ev, void* destination, long count)
- {
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- FW_CByteArray byteArray;
-
- fStorageUnitView->GetValue(ev, count, byteArray);
- byteArray.CopyBuffer(destination, count);
- #elif FW_OPENDOC_VERSION == FW_OPENDOC_DR2
- FW_CByteArray byteArray(destination, count);
-
- fStorageUnitView->GetValue(ev, byteArray);
- #else
- fStorageUnitView->GetValue(ev, count, destination);
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::GetWritableBytes
- //----------------------------------------------------------------------------------------
-
- long FW_CPrivSUSinkRep::GetWritableBytes(Environment* ev)
- {
- FW_UNUSED(ev);
- return 0x7FFFFFFFL;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivSUSinkRep::Write(Environment* ev, void* source, long count)
- {
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR2
- FW_CByteArray byteArray(source, count);
-
- fStorageUnitView->SetValue(ev, byteArray);
- #else
- fStorageUnitView->SetValue(ev, count, source);
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivSUSinkRep::Acquire
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivSUSinkRep::Acquire(Environment* ev)
- {
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- if (fStorageUnitView)
- fStorageUnitView->GetStorageUnit(ev)->Acquire(ev);
- #endif
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__InitFromStorageUnitView
- //----------------------------------------------------------------------------------------
-
- /*
- * Create a sink attached to the storage unit view.
- * The sink does not assume ownership of the view.
- */
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__InitFromStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev,
- ODStorageUnitView* storageUnitView)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
-
- FW_SOM_TRY
- {
- somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnitView));
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__InitFromStorageUnitAndProperty
- //----------------------------------------------------------------------------------------
-
- /*
- * Create a sink attached to the given (storageUnit, propertyName, valueType).
- */
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__InitFromStorageUnitAndProperty(FW_OStorageUnitSink *somSelf, Environment *ev,
- ODStorageUnit* storageUnit,
- ODPropertyName propertyName,
- ODValueType valueType)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
-
- FW_SOM_TRY
- {
- somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnit, propertyName, valueType));
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__GetStorageUnitView
- //----------------------------------------------------------------------------------------
-
- SOM_Scope ODStorageUnitView* SOMLINK FW_OStorageUnitSink__GetStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev)
- {
- FW_UNUSED(ev);
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- return rep.fStorageUnitView;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__somInit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__somInit(FW_OStorageUnitSink *somSelf)
- {
- FW_UNUSED(somSelf);
- // FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
-
- // FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somInit(somSelf);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__somUninit
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__somUninit(FW_OStorageUnitSink *somSelf)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
-
- FW_SOM_UNINIT_TRY
- {
- delete somThis->fRep;
- // FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somUninit(somSelf);
- }
- FW_SOM_UNINIT_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__Read
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__Read(FW_OStorageUnitSink *somSelf, Environment *ev,
- void* destination,
- long count)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- rep.Read(ev, destination, count);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__GetWritableBytes
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OStorageUnitSink__GetWritableBytes(FW_OStorageUnitSink *somSelf, Environment *ev)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- return rep.GetWritableBytes(ev);
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__Write
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__Write(FW_OStorageUnitSink *somSelf, Environment *ev,
- void* source,
- long count)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- rep.Write(ev, source, count);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__GetLength
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OStorageUnitSink__GetLength(FW_OStorageUnitSink *somSelf, Environment *ev)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- return rep.GetLength(ev);
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__SetLength
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__SetLength(FW_OStorageUnitSink *somSelf, Environment *ev,
- long length)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- rep.SetLength(ev, length);
- }
- FW_SOM_CATCH
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__GetPosition
- //----------------------------------------------------------------------------------------
-
- SOM_Scope long SOMLINK FW_OStorageUnitSink__GetPosition(FW_OStorageUnitSink *somSelf, Environment *ev)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- return rep.GetPosition(ev);
- }
- FW_SOM_CATCH
- return 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_OStorageUnitSink__SetPosition
- //----------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK FW_OStorageUnitSink__SetPosition(FW_OStorageUnitSink *somSelf, Environment *ev,
- long position)
- {
- FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
- FW_CPrivSUSinkRep& rep = *somThis->fRep;
-
- FW_SOM_TRY
- {
- rep.SetPosition(ev, position);
- }
- FW_SOM_CATCH
- }
-